package com.lesent.kafka.spring.listener;

import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.listener.ErrorHandler;
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @author shengtao
 * @Description:
 * @date 2018/12/20 14:37
 */
@Component
public class KafkaErrorHandler implements KafkaListenerErrorHandler {

    @Override
    public Object handleError(Message<?> message, ListenerExecutionFailedException e) throws Exception {
        System.out.println("错误："+e.toString()+"    msg:"+message);
        return null;
    }

    @Override
    public Object handleError(Message<?> message, ListenerExecutionFailedException exception, Consumer<?, ?> consumer) throws Exception {
        System.out.println("错误："+exception.toString()+"    msg:"+message+ "   consumer:"+consumer.toString());
        return null;
    }
}
